package test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class MyJframe extends JFrame {
    protected  MyJframe() {
        super("菜单应用程序");
    }
    public void init() {
        //设置背景颜色要先获得一个容器
        Container container = this.getContentPane();
        container.setBackground(Color.WHITE);
        setBounds(100,200,300,400);
        JPanel panel = new JPanel();
        //对panel设置初始位置、坐标、颜色相对于frame
        panel.setBounds(1,1,300,200);
        panel.setBackground(new Color(253, 250, 250, 218));
        add(panel);

        JButton jButton = new JButton("文件");
        panel.add(jButton);
        setLayout(new FlowLayout());

        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //写一个弹窗的窗口

            }
        });
        //设置标签居中
        //label.setHorizontalAlignment(SwingConstants.CENTER);
        //add(label);
        //设置可见性
        setVisible(true);
        //设置关闭监听
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }
}